package me.xsomnus.study.jike.algs.dynamic_programming;

/**
 * @author @xsomnus666_xiawenye★
 * @since 2019/11/25 11:11 下午
 * 脚踏实地,仰望星空
 * f(n) = f(n-1) + f(n-2)
 */
public class Fibonacci {

    private static final int count = 10;

    private int n;

    public Fibonacci(int n) {
        this.n = n;
    }

    public int val() {
        if (n == 1 || n == 2) {
            return 1;
        }
        return new Fibonacci(n-1).val() + new Fibonacci(n-2).val();
    }

    public static void main(String[] args) {
        for (int i = 1; i < count; i++) {
            Fibonacci fibonacci = new Fibonacci(i);
            System.out.println(fibonacci.val());
        }


        int[] memory = new int[count];
        memory[0] = 1;
        memory[1] = 1;

        for (int i = 2; i < count; i++) {
            memory[i] = memory[i-1] + memory[i-2];
        }

        for (int value : memory) {
            System.out.println(value);
        }
    }
}
